package start.spring.basic.response;

import start.spring.basic.page.PageResult;

public class ResponsePage<T> {

	public static final String DEFAULT_SUCCESS_CODE = "200";
    public static final String DEFAULT_ERROR_CODE = "500";
    
	public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功";
    public static final String DEFAULT_ERROR_MESSAGE = "系统异常";
    
    private String code;
    private String msg;
    private PageResult<T> page;
    
    public ResponsePage() {}
    
    public ResponsePage(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    
    public ResponsePage(String code, String msg, PageResult<T> page) {
        this.code = code;
        this.msg = msg;
        this.page = page;
    }
    
    public static <T> ResponsePage<T> success(PageResult<T> page) {
        return new ResponsePage<>(DEFAULT_SUCCESS_CODE,DEFAULT_SUCCESS_MESSAGE,page);
    }
    
    public static <T> ResponsePage<T> success(String message,PageResult<T> data) {
        return new ResponsePage<>(DEFAULT_SUCCESS_CODE, message, data);
    }
    
    public static <T> ResponsePage<T> error() {
        return new ResponsePage<>(DEFAULT_ERROR_CODE,DEFAULT_ERROR_MESSAGE);
    }

    public static <T> ResponsePage<Object> error(String message) {
        return new ResponsePage<>(DEFAULT_ERROR_CODE,message);
    }

    public static <T> ResponsePage<T> error(String code, String message) {
        return new ResponsePage<>(code, message);
    }
    
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public PageResult<T> getPage() {
		return page;
	}

	public void setPage(PageResult<T> page) {
		this.page = page;
	}
	
}
